{% extends 'base.html' %}
{% block content %}
<div class="layui-card">
    <div class="layui-card-header">
        ETF基金列表
        <div style="float:right;">
            <a href="/collect/ETF" class="layui-btn layui-btn-sm">采集数据</a>
            <a href="/export/etf" class="layui-btn layui-btn-sm layui-btn-primary">导出Excel</a>
        </div>
    </div>
    <div class="layui-card-body">
        <!-- 搜索框 -->
        <form class="layui-form" action="" method="get">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <input type="text" name="search" placeholder="搜索名称/代码/标签" autocomplete="off" class="layui-input" value="{{ request.args.get('search', '') }}">
                </div>
                <div class="layui-inline">
                    <button class="layui-btn" lay-submit>搜索</button>
                </div>
            </div>
        </form>
        
        <!-- 数据表格 -->
        <table class="layui-table">
            <thead>
                <tr>
                    <th>名称</th>
                    <th>代码</th>
                    <th>最新价</th>
                    <th>日涨幅</th>
                    <th>溢价率</th>
                    <th>分类</th>
                    <th>运作费率</th>
                    <th>基金公司</th>
                    <th>上市日期</th>
                    <th>规模(亿)</th>
                    <th>更新时间</th>
                </tr>
            </thead>
            <tbody>
            {% for fund in funds %}
                <tr>
                    <td>{{ fund.name }}</td>
                    <td>{{ fund.code }}</td>
                    <td>{{ "%.3f"|format(fund.close) if fund.close else '-' }}</td>
                    <td>{{ "%.2f"|format((fund.rate/100-100)) if fund.rate else '-' }}%</td>
                    <td>{{ "%.2f"|format((fund.premium/100-100)) if fund.premium else '-' }}%</td>
                    <td>{{ fund.tag }}</td>
                    <td>{{ fund.mtexp }}</td>
                    <td>{{ fund.fundfirm }}</td>
                    <td>{{ fund.listdate }}</td>
                    <td>{{ "%.2f"|format(fund.scale) if fund.scale else '-' }}</td>
                    <td>{{ fund.updated_at.strftime('%Y-%m-%d %H:%M:%S') }}</td>
                </tr>
            {% endfor %}
            </tbody>
        </table>
    </div>
</div>
{% endblock %}